<template>
  <div>
    <el-card shadow="never">
      <div slot="header"><div class="demo-basic--circle">
        <div class="block"><el-avatar :size="100" :src="imgs"></el-avatar></div>
      </div><span style="margin-left: 15px">密码修改</span></div>
      <div style="min-height:30vh;width:30%">
        <el-form size="small"  ref="form" :model="form" label-width="100px">
          <el-form-item label="旧密码">
            <el-input v-model="form.password"></el-input>
          </el-form-item>
          <el-form-item label="新密码">
            <el-input v-model="form.new_password" show-password title="6-20个字符"></el-input>
          </el-form-item>
          <el-form-item label="确认新密码">
            <el-input v-model="form.new_password_verify" show-password></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="success" @click="onSubmit()">确认修改</el-button>
          </el-form-item>
        </el-form>
      </div>
    </el-card>
  </div>
</template>
<script>
import img from "../../assets/imgs/timg.png"
export default {
  data() {
    return {
      imgs:img,
      form: {
        password: "",
        new_password: "",
        new_password_verify: "",
      },
    };
  },
  methods: {
    onSubmit() {
      //先验证旧密码是否正确
      if(this.form.new_password != this.form.new_password_verify){
        this.$message.error("两次输入的密码不一致");
        this.form.new_password_verify = "";
        this.form.new_password = "";
        this.form.password = "";
      }else if(this.form.password == this.form.new_password){
        this.$message.error("新旧密码相同");
        this.form.new_password_verify = "";
        this.form.new_password = "";
        this.form.password = "";
      } else {
        this.$axios({
          url:this.$axios.defaults.baseURL+"/student/setpwd",
          method:"get",
          params:{
            uid:sessionStorage.getItem(sessionStorage.getItem("user_label")+"uid"),
            old:this.form.password,
            npwd:this.form.new_password
          }
        }).then(res=>{
          if(res.data.status){
            this.$message.success(res.data.msg);
          }else {
            this.$message.error(res.data.msg);
          }
          this.form.new_password_verify = "";
          this.form.new_password = "";
          this.form.password = "";
        })
      }
    },
  },
};
</script>
<style scoped>

</style>